package com.customization.huangwm.cronJob;

import java.util.ArrayList;
import java.util.List;

import org.apache.axis.components.logger.LogFactory;
import org.apache.commons.logging.Log;

import weaver.interfaces.schedule.BaseCronJob;

public abstract class AbstractCronJob extends BaseCronJob {

    private List<String> currTasks = new ArrayList<String>();    // true 表示正在执行上一轮任
    private Log log = new LogFactory().getLog("custom_huangwm");

    @Override
    public void execute() {
        if (currTasks.contains(this.getClass().getName())) {
            log.info("上一轮计划任务未结束=>>>" + this.getClass().getName());
            return;
        }

        long time = System.currentTimeMillis();
        try {
            log.info("计划任务开始=>>>" + this.getClass().getName());
            currTasks.add(this.getClass().getName());
            start();
        } catch (Exception e) {
            log.info("计划任务异常 " + e.getMessage());
            e.printStackTrace();
        } finally {
            currTasks.remove(this.getClass().getName());
            time = System.currentTimeMillis() - time;
            log.info("总耗时（秒）：" + (time / 1000));
            log.info("计划任务结束。");
        }
    }

    public abstract void start() throws Exception;
}
